﻿@namespace Masa.Stack.Components.Layouts
@using Masa.Stack.Components.Forms;
@inherits MasaComponentBase

<SSimpleDialog @bind-Value="_visible"
               HideCancel=true
               OnCancel="HandleOnCancel">
    <CascadingValue Value="this">
        <STabSheets @bind-Value="_value" Tabs="@Tabs" Height="520" Class="pa-0" OnChange="ResetFields">
            <MTabItem Value="Tabs[0]">
                <PhoneNumberValidateForm @ref="_phoneNumberValidateForm"></PhoneNumberValidateForm>
            </MTabItem>
            <MTabItem Value="Tabs[1]" Disabled>
                <EmailValidateForm @ref="_emailValidateForm"></EmailValidateForm>
            </MTabItem>
        </STabSheets>
    </CascadingValue>
</SSimpleDialog>

@code {

    private bool _visible;
    private PhoneNumberValidateForm? _phoneNumberValidateForm;
    private EmailValidateForm? _emailValidateForm;
    private List<string> Tabs => new List<string>() { T("SetPasswordBySMS"), T("SetPasswordByEmail") };
    private string _value = "";

    [CascadingParameter]
    public UpdatePasswordModal UpdatePasswordModal { get; set; } = null!;

    protected override void OnInitialized()
    {
        _value = T("SetPasswordBySMS");
    }

    internal void ResetFields()
    {
        _phoneNumberValidateForm?.ResetFields();
        _emailValidateForm?.ResetFields();
    }

    internal void HandleOnCancel()
    {
        _visible = false;
        ResetFields();
        StateHasChanged();
    }

    internal void Open()
    {
        _visible = true;
        StateHasChanged();
    }
}
